package com.winning.devops.base.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * @author chensj
 * @title
 * @project spring-boot-cli
 * @package com.winning.devops.base.config
 * @date: 2019-04-03 16:39
 */
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        // 添加服务端点 浏览器链接这个地址
        registry.addEndpoint("/hello").setAllowedOrigins("*").withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        // 设置浏览器接收的服务前缀,同时也是后台服务推送的前缀
        registry.enableSimpleBroker("/topic", "/user");
        // 设置浏览器发送消息的服务前缀,也就是后台服务接收前台信息的前缀
        registry.setApplicationDestinationPrefixes("/app");
    }
}
